namespace PcapDotNet.Packets.IpV6
{
    /// <summary>
    /// RFC 4866.
    /// <pre>
    /// +-----+-------------+--------------+
    /// | Bit | 0-7         | 8-15         |
    /// +-----+-------------+--------------+
    /// | 0   | Option Type | Opt Data Len |
    /// +-----+-------------+--------------+
    /// | 16  | Care-of Keygen Token       |
    /// |     |                            |
    /// |     |                            |
    /// |     |                            |
    /// +-----+----------------------------+
    /// </pre>
    /// </summary>
    [IpV6MobilityOptionTypeRegistration(IpV6MobilityOptionType.CareOfTest)]
    public sealed class IpV6MobilityOptionCareOfTest : IpV6MobilityOptionULong
    {
        /// <summary>
        /// Creates an instance from care of keygen token.
        /// </summary>
        /// <param name="careOfKeygenToken">Contains the care-of keygen token generated by the correspondent node.</param>
        public IpV6MobilityOptionCareOfTest(ulong careOfKeygenToken)
            : base(IpV6MobilityOptionType.CareOfTest, careOfKeygenToken)
        {
        }

        /// <summary>
        /// Contains the care-of keygen token generated by the correspondent node.
        /// </summary>
        public ulong CareOfKeygenToken
        {
            get { return Value; }
        }

        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            ulong careOfKeygenToken;
            if (!Read(data, out careOfKeygenToken))
                return null;

            return new IpV6MobilityOptionCareOfTest(careOfKeygenToken);
        }

        private IpV6MobilityOptionCareOfTest() 
            : this(0)
        {
        }
    }
}